package 双周赛;

import java.util.HashSet;
import java.util.Set;

/**
 *
 */
public class 第97场双周赛 {

    public static void main(String[] args) {

//        System.out.println(separateDigits(new int[]{34, 23}));
//
//        System.out.println(maxCount(new int[]{1, 6, 5}, 5, 6));

        //9,5380,5383,5385,5391,5418,5425,5429,5432,5479,5486,5490,5502,5502,5505,5506,5509,5515,5518,5519,5521,5526,5528,5533,5536,5536,5538,5555,5556,5557,5557,5566,5571,5580,5585,5596,5604,5619,5634,5649,5668,5694,5696,5699,5701,5704,5709,5732,5745,5745,5746,5749,5762,5766,5766,5770,5773,5796,5810,5817,5823,5838,5843,5846,5860,5869,5872,5877,5880,5896,5899,5902,5905,5910,5913,5913,5915,5923]
        //220
        //输出：
        //252
        //预期：
        //74
        System.out.println(maximizeWin(new int[]{2616, 2618, 2620, 2621, 2626, 2635, 2657, 2662, 2662, 2669, 2671, 2693, 2702, 2713, 2714, 2718, 2730, 2731, 2750, 2756, 2772, 2773, 2775, 2785, 2795, 2805, 2811, 2813, 2816, 2823, 2824, 2824, 2826, 2830, 2833, 2857, 2885, 2898, 2910, 2919, 2928, 2941, 2942, 2944, 2965, 2967, 2970, 2973, 2974, 2975, 2977, 3002, 3007, 3012, 3042, 3049, 3078, 3084, 3089, 3090, 3094, 3097, 3114, 3124, 3125, 3125, 3144, 3147, 3148, 3174, 3197, 3255, 3262, 3288, 3291, 3316, 3320, 3322, 3331, 3342, 3378, 3412, 3412, 3416, 3420, 3427, 3428, 3446, 3452, 3472, 3479, 3483, 3488, 3500, 3516, 3522, 3531, 3532, 3540, 3540, 3544, 3557, 3570, 3580, 3592, 3597, 3597, 3601, 3615, 3631, 3640, 3645, 3673, 3677, 3681, 3683, 3685, 3718, 3738, 3746, 3758, 3769, 3797, 3802, 3815, 3832, 3839, 3851, 3864, 3888, 3889, 3901, 3902, 3910, 3913, 3933, 3940, 3961, 3974, 3988, 4003, 4013, 4019, 4023, 4026, 4047, 4060, 4065, 4072, 4073, 4082, 4084, 4109, 4132, 4139, 4143, 4145, 4146, 4155},
                6641));

    }

    public static int[] separateDigits(int[] nums) {
        StringBuilder stringBuilder = new StringBuilder();

        for (int num : nums) {
            stringBuilder.append(num);
        }

        int[] ans = new int[stringBuilder.length()];
        char[] chars = stringBuilder.toString().toCharArray();
        for (int i = 0; i < chars.length; i++) {
            ans[i] = chars[i] - '0';
        }
        return ans;
    }

    public static int maxCount(int[] banned, int n, int maxSum) {
        Set<Integer> set = new HashSet<>();
        for (int b : banned) {
            set.add(b);
        }
        int cnt = 0;
        int curN = 1, curSum = 0;
        while (curN <= n && curN + curSum <= maxSum) {
            if (set.contains(curN)) {
                curN++;
                continue;
            }
            curSum += curN;
            curN++;
            cnt++;
        }
        return cnt;
    }

    public static int maximizeWin(int[] prizePositions, int k) {
        if (prizePositions.length <= k + 1) {
            return prizePositions.length;
        }
        int l1 = 0, r1 = 0;
        int ans = 0;
        Set<Integer> set = new HashSet<>();
        int left = 0;
        while (left < prizePositions.length) {
            int right = left;
            while (right < prizePositions.length) {
                set.add(prizePositions[right]);
                if (set.size() > k + 1) {
                    break;
                }
                right++;
            }
            if (set.size() > k || right == prizePositions.length) {
                if (right - left > r1 - l1) {
                    l1 = left;
                    r1 = right - 1;
                }

            }
        }
        return ans;
    }


}
